package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Description:
 *
 * @Author: yankaiyue
 * @Create: 2025/8/8 9:11
 * @Version: 1.0
 */
@RestController
public class OrderInfoController {
    @Autowired
    OrderInfoService orderInfoService;
    @RequestMapping("/getListBO")
    public JSONObject getListBO(){
        List<Map> list = orderInfoService.getListBO();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray columns = new JSONArray();
            JSONObject columns1 = new JSONObject();
            columns1.put("name","序号");
            columns1.put("id","id");
            columns.add(columns1);
        JSONObject columns2 = new JSONObject();
        columns2.put("name","章节名称");
        columns2.put("id","chapter_name");
        columns.add(columns2);
        JSONObject columns3 = new JSONObject();
        columns3.put("name","播放次数");
        columns3.put("id","num");
        columns.add(columns3);
        JSONObject columns4 = new JSONObject();
        columns4.put("name","播放时长");
        columns4.put("id","position_sec_Long");
        columns.add(columns4);
        JSONObject columns5 = new JSONObject();
        columns5.put("name","观看人数");
        columns5.put("id","user_id_num");
        columns.add(columns5);
        JSONObject columns6 = new JSONObject();
        columns6.put("name","人均观看人数");
        columns6.put("id","view_hour");
        columns.add(columns6);
        data.put("columns",columns);
        JSONArray rows = new JSONArray();
        for (Map map : list) {
            JSONObject row = new JSONObject();
            row.put("id",map.get("id"));
            row.put("chapter_name",map.get("chapter_name"));
            row.put("num",map.get("num"));
            row.put("position_sec_Long",map.get("position_sec_Long"));
            row.put("user_id_num",map.get("user_id_num"));
            row.put("view_hour",map.get("view_hour"));
            rows.add(row);
        }
        data.put("rows",rows);
        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/getListScore")
    public JSONObject getListScore() {
        List<Map> list = orderInfoService.getListScore();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");
        JSONArray data = new JSONArray();
        for (Map map : list) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("score"));
            jsonObject1.put("value",map.get("num"));
            data.add(jsonObject1);
        }
        jsonObject.put("data",data);
        return jsonObject;
    }
@RequestMapping("/getListProvince")
    public JSONObject getListProvince(){
        List<Map> list=orderInfoService.getListProvince();
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("status", 0);
    jsonObject.put("msg", "");
    JSONObject data = new JSONObject();
    JSONArray mapData = new JSONArray();
    for (Map map : list) {
        JSONObject mapData1 = new JSONObject();
        mapData1.put("name",map.get("name"));
        mapData1.put("value",map.get("total_amount"));
        mapData.add(mapData1);
    }
    data.put("mapData",mapData);
    data.put("valueName","订单总额");
    jsonObject.put("data",data);
    return jsonObject;
}
    @RequestMapping("/getListAmount")
    public JSONObject getListAmount() {
        List<Map> list = orderInfoService.getListAmount();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");
        JSONArray data = new JSONArray();
        for (Map map : list) {
            jsonObject.put("data",map.get("final_amount_total"));
        }

        return jsonObject;
    }
}
